package com.service.impl;

import com.bean.entity.AnswerInfo;
import com.bean.pojo.PageAssistant;
import com.bean.vo.AllStudentScoreVo;
import com.bean.vo.AnswerInfoVo;
import com.dao.AnswerInfoMapper;
import com.service.AnswerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 答复基础业务逻辑实现
 */
@Service
public class AnswerInfoServiceImpl implements AnswerInfoService {

    @Autowired
    private AnswerInfoMapper answerInfoMapper;

    @Override
    public int save(AnswerInfo t) throws Exception {
        return answerInfoMapper.insert(t);
    }

    @Override
    public int remove(AnswerInfo t) throws Exception {
        return answerInfoMapper.delete(t);
    }

    @Override
    public int modify(AnswerInfo t) throws Exception {
        return answerInfoMapper.update(t);
    }

    @Override
    public AnswerInfoVo unique(AnswerInfo t) throws Exception {
        List<AnswerInfoVo> answerInfoVoList = answerInfoMapper.select(t);
        if (answerInfoVoList.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return answerInfoVoList.get(0);
    }

    @Override
    public List<AnswerInfoVo> query(AnswerInfo t) {
        return answerInfoMapper.select(t);
    }

    @Override
    public PageAssistant<AnswerInfoVo> queryByPage(Map<String, Object> map, PageAssistant<AnswerInfoVo> pa) {
        //查询并设置总记录数
        pa.setCount(answerInfoMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(answerInfoMapper.selectByPage(map));
        return pa;
    }
}
